package LeetCode.leetcode;

/**
 * 反转整数
 *
 * @author: leiwenkang02@meituan.com
 * @date: 2018/9/8
 * @time: 15:13
 */
public class Test07整数反转 {
    public static void main(String[] args) {
        int a = Integer.MAX_VALUE;
        int b = a + 1;
        System.out.println(b);
        System.out.println(b / 10);
        System.out.println(reverse(-123));
    }


    public static int reverse(int x) {
        int result = 0;
        while (x != 0) {
            int tail = x % 10;
            int newResult = result * 10 + tail;
            if ((newResult - tail) / 10 != result) {
                return 0;
            }
            result = newResult;
            x = x / 10;
        }
        return result;
    }
}
